package service

import (
	"api-gateway/basic/config"
	"api-gateway/handler/request"
	"api-gateway/pkg"
	"fmt"
	"github.com/gin-gonic/gin"
	"math/rand"
	"net/http"
	"strconv"
	"time"
)

func Sms(c *gin.Context) {

	send := request.Sms{}
	err := c.ShouldBind(&send)
	if err != nil {
		return
	}
	code := rand.Intn(900000) + 100000
	sprintf := fmt.Sprintf("短信发送:%v", send.Mobile)
	config.Rdb.Set(config.Ctx, strconv.Itoa(code), sprintf, time.Minute*5)
	_, err = pkg.SendSms(send.Mobile, strconv.Itoa(code))
	if err != nil {
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "短信发送成功",
	})
}
